package com.css.dzj.dzjdzqs.modules.datafromjcss.service.impl;

import com.alibaba.fastjson.JSON;
import com.css.dzj.dzjdzqs.common.util.HttpClientUtil;
import com.css.dzj.dzjdzqs.modules.datafromjcss.entity.VenueEntity;
import com.css.dzj.dzjdzqs.modules.datafromjcss.mapper.VenueMapper;
import com.css.dzj.dzjdzqs.modules.datafromjcss.service.VenueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public class VenueServiceImpl implements VenueService {
    @Value("${JCSS_URL}")
    private String jcssUrl;
    @Autowired
    VenueMapper venueMapper;
    @Override
    @Transactional
    public void addJcssVenue()  {
        try {
            String list = HttpClientUtil.doGet(jcssUrl + "/venue/queryAllJcssMsg");
            List<VenueEntity> results = JSON.parseArray(list, VenueEntity.class);
            for (VenueEntity result : results) {
                VenueEntity venueEntity = new VenueEntity();
                venueEntity.setPlaceId(result.getPlaceId());
                venueEntity.setPlaceName(result.getPlaceName());
                venueEntity.setArea(result.getArea());
                venueEntity.setAreaNumber(result.getAreaNumber());
                venueEntity.setResponsibleDept(result.getResponsibleDept());
                venueEntity.setEnterpriseCreditCode(result.getEnterpriseCreditCode());
                venueEntity.setChargePerson(result.getChargePerson());
                venueEntity.setCertificateType(result.getCertificateType());
                venueEntity.setCertificateNumber(result.getCertificateNumber());
                venueEntity.setContactTel(result.getContactTel());
                venueEntity.setPlacePurpose(result.getPlacePurpose());
                venueEntity.setPlaceScale(result.getPlaceScale());
                venueEntity.setStartDate(result.getStartDate());
                venueEntity.setDeviceLifetime(result.getDeviceLifetime());
                venueMapper.save(venueEntity);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
